package com.xiaozhen.blog.event;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaozhen.blog.entity.Comment;
import com.xiaozhen.blog.entity.Event;
import com.xiaozhen.blog.entity.User;
import com.xiaozhen.blog.service.CommentService;
import com.xiaozhen.blog.service.EventService;
import com.xiaozhen.blog.service.UserService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @create 2023-05-23 15:46
 * 消费者
 */
@Component
public class EventConsumer {



    @Autowired
    private EventService eventService;

    //    @RabbitListener(queues = "like.queue")
    public void receiveLikeMessage(String message) {
        System.out.println("收到点赞消息：" + message);
        // 处理点赞消息
    }

    @RabbitListener(queues = "comment.queue")
    public void receiveCommentMessage(String message) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        Event event = objectMapper.readValue(message, Event.class);
        // TODO 更新数据库
        eventService.add(event);
    }

    @RabbitListener(queues = "follow.queue")
    public void receiveFollowMessage(String message) {
        System.out.println("收到关注消息：" + message);
        // 处理关注消息
    }
}
